﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class BeerBottleCapBehaviour : MonoBehaviour
{
    public UnityEvent onPlayAnimation;
    private bool flag;
    // Start is called before the first frame update
    void Start()
    {
        Player.Instance.onFootTriggerEnter.AddListener(col => 
        {
            Debug.Log(col.tag);

            if (col.CompareTag("Beer Bottle Cap") && !flag)
            {
                flag = true;
                Debug.Log("123666");
                Invoke("PlayAnimation", 3);
            }
        });       
    }

    void PlayAnimation()
    {
        Player.Instance.transform.DOMoveY(70, 3).SetEase(Ease.OutCubic).onComplete += () => 
        {
            var cover = GameObject.FindGameObjectsWithTag("Cover");
            foreach (var item in cover)
            {
                Destroy(item);
            }
            onPlayAnimation?.Invoke();
            Player.Instance.GetComponent<FPS>().ResetGravity();
        };
    }
}
